<!-- eslint-disable vue/multi-word-component-names -->
<template>
    <div>
        <div id="container">

            <div id="header">
            </div>
        </div>
        <div id="container">
            <div id="content2">
                <table width="100%" height="41" border="0" align="center" cellpadding="0" cellspacing="0">
                    <tr>
                        <td width="15" height="18" align="left" valign="top">
                            <div align="left"></div>
                        </td>
                        <td width="385" align="left" valign="bottom" class="12">&nbsp;</td>
                    </tr>
                    <tr>
                        <td height="4" colspan="2" align="left" valign="bottom"></td>
                    </tr>
                    <tr>
                        <td height="15" align="left" valign="top">&nbsp;</td>
                        <td height="15" align="left" valign="top" class="12">




                            <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px"
                                class="demo-ruleForm">

                                <el-form-item label="原始密码" prop="oldPass">
                                    <el-input type="password" v-model="ruleForm.oldPass" autocomplete="off"
                                        @blur="check()">
                                    </el-input>
                                </el-form-item>

                                <el-form-item label="新密码" prop="newPass">
                                    <el-input type="password" v-model="ruleForm.newPass" autocomplete="off">
                                    </el-input>
                                </el-form-item>

                                <el-form-item label="重复密码" prop="checkPass">
                                    <el-input type="password" v-model="ruleForm.checkPass" auto-complete="off">
                                    </el-input>
                                </el-form-item>

                                <el-form-item>
                                    <el-button type="primary" @click="submitForm()">提交</el-button>

                                </el-form-item>
                            </el-form>





                            <br />
                            <div class="table_wz"></div>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
</template>

<script>

import axios from '../../utils/Myaxios'

const options = {
    data() {
        var validatePass = (rule, value, callback) => {
            if (value === '') {
                callback(new Error('请输入密码'));
            }
        }
        var validatePass2 = (rule, value, callback) => {
            if (value === '') {
                callback(new Error('请输入密码'));
            }
        }
        var checkPass1 = (rule, value, callback) => {
            if (value === '') {
                callback(new Error('请输入密码'));
            } else if (value !== this.ruleForm.newPass) {
                callback(new Error('两次输入密码不一致!'));
            } else {
                callback();
            }
        }

        return {
            uid: 2,
            ruleForm: {
                oldpass: '',
                newPass: '',
                checkPass: ''
            },
            rules: {
                oldpass: [
                    { validator: validatePass, trigger: 'blur' }
                ],
                newPass: [
                    { validator: validatePass2, trigger: 'blur' }
                ],
                checkPass: [
                    { validator: checkPass1, trigger: 'blur' }
                ]
            }
        }
    },
    methods: {

        async check() {
            const _axios = axios.create({
                baseURL: 'http://localhost:8080',
                withCredentials: true
            })
            const resp = await _axios.get('/experts/select', {
                params: {
                    uid: this.uid
                }
            })
            if (this.newPass == !resp.data.data.password) {
                alert("错误")
            } else {
                alert("正确")
            }

        },


        async submitForm() {
            const _axios = axios.create({
                baseURL: 'http://localhost:8080',
                withCredentials: true
            })

            await _axios.post('/experts/updatePassword', {}, {
                params: {
                    password: this.ruleForm.newPass,
                    uid: this.uid
                }
            }

            )

        }
    }





}
export default options;
</script>

<style>

</style>